package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.CompanyStore;
import com.vne.skyemart.service.CompanyStoreService;

@Controller
@SessionAttributes
@RequestMapping("/companyStore")
public class CompanyStoreController {
	@Autowired
	private CompanyStoreService companyStoreService;
	
	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView saveCompanyStore(@ModelAttribute(" companyStore") CompanyStore companyStore,
			BindingResult result) {
		 companyStoreService.addCompanyStore(companyStore);
		return new ModelAndView("redirect:/companyStore.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listCartItem(Model model) {
		model.addAttribute("companyStore",  companyStoreService.listCompanyStore());

		return "companyStoreList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addCompanyStore(@ModelAttribute("companyStore") CompanyStore companyStore,
			BindingResult result) {
		return new ModelAndView("addCompanyStore");
	}
}
